home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / oath.lha / oath / test / stable.cc < prev    next >
C/C++ Source or Header  |  1991-08-29  |  3KB  |  88 lines

  1. #include "oath/oath.h"
  2.  
  3. #include "timer.h"
  4.  
  5. #include <iostream.h>
  6.  
  7. //***************************************************************************
  8.  
  9. #define COUNT 1000000
  10.  
  11. const int&  foo (const int&  I) {return I;}
  12. const objA& foo (const objA& O) {return O;}
  13.  
  14. main()
  15.    {stringTableA ST7  = stringTableA::make(7);
  16.     stringTableA ST11 = stringTableA::make(11);
  17.  
  18.     cout << "sizeof(stringTableA) = " << sizeof(stringTableA) << endl;
  19.     cout << "sizeof(stringTableG) = " << sizeof(stringTableG) << endl;
  20.     cout << "sizeof(stNodeP)      = " << sizeof(stNodeP)      << endl;
  21.  
  22.     stringTokenA Declaration = stringTokenA::make("Declaration");
  23.     stringTokenA Definition  = stringTokenA::make("Definition");
  24.     stringTokenA Initializer = stringTokenA::make("Initializer");
  25.  
  26.     cout << endl;
  27.  
  28.     cout << Declaration.string() << " hash("  << Declaration.hash()      << ")"
  29.                  << " mod7("  << Declaration.hash() % 7  << ")"
  30.                  << " mod11(" << Declaration.hash() % 11 << ")"
  31.                  << endl;
  32.     cout << Definition.string() << "  hash( " << Definition.hash()       << ")"
  33.                  << " mod7("  << Definition.hash()  % 7  << ")"
  34.                  << " mod11(" << Definition.hash()  % 11 << ")"
  35.                  << endl;
  36.     cout << Initializer.string() << " hash("  << Initializer.hash()      << ")"
  37.                  << " mod7("  << Initializer.hash() % 7  << ")"
  38.                  << " mod11(" << Initializer.hash() % 11 << ")"
  39.                  << endl;
  40.  
  41.     tokenA DeclValue = localTokenA::make();
  42.     tokenA DefnValue = localTokenA::make();
  43.     tokenA InitValue = localTokenA::make();
  44.  
  45.     ST7.insert(Declaration, DeclValue);
  46.     ST7.insert(Definition,  DefnValue);
  47.     ST7.insert(Initializer, InitValue);
  48.  
  49.     ST11.insert(Declaration, DeclValue);
  50.     ST11.insert(Definition,  DefnValue);
  51.     ST11.insert(Initializer, InitValue);
  52.  
  53.     cout << endl;
  54.  
  55.     objA  Value;
  56.     int   I, J;
  57.     timer Timer;
  58.  
  59.     Timer.start();
  60.     for(I = 0; I < COUNT; ++I)
  61.         J = foo(I);
  62.     Timer.split();
  63.     cout << COUNT << " retrievals from int I ------ " << Timer.cpu() << " ms"
  64.          << endl;
  65.  
  66.     Timer.start();
  67.     for(I = 0; I < COUNT; ++I)
  68.         Value = foo(DeclValue);
  69.     Timer.split();
  70.     cout << COUNT << " retrievals from DeclValue -- " << Timer.cpu() << " ms"
  71.          << endl;
  72.  
  73.     Timer.start();
  74.     for(I = 0; I < COUNT; ++I)
  75.         Value = foo(ST7.assoc(Declaration));
  76.     Timer.split();
  77.     cout << COUNT << " retrievals from ST7 -------- " << Timer.cpu() << " ms"
  78.          << endl;
  79.  
  80.     Timer.start();
  81.     for(I = 0; I < COUNT; ++I)
  82.         Value = foo(ST11.assoc(Declaration));
  83.     Timer.split();
  84.     cout << COUNT << " retrievals from ST11 ------- " << Timer.cpu() << " ms"
  85.          << endl;
  86.  
  87.    }
  88.